<?php defined('SYSPATH') OR die('No direct access allowed.');
class date extends date_Core
{
	/**
	 * 获取发布日期，如3天前，5分钟前等等
	 * @param timestamp
	 * @return string 如3天前,5分钟前
	 */
	public static function format($time)
	{
		$arr = self::timespan($time,time());
		if($arr['years']!==0) return date('Y年m月d日',$time);
		if($arr['months']!==0) return date('Y年m月d日',$time);
		//if($arr['weeks']!==0) return $arr['weeks'].'个星期前';
		if($arr['days']!==0)
		{
		   	return (int)$arr['weeks']*7 + (int)$arr['days'].'天前';
		}
		else
		{
			if($arr['weeks']!==0)
			{
				return ($arr['weeks']*7).'天前';
			}
		}
		if($arr['hours']!==0) return $arr['hours'].'小时前';
		if($arr['minutes']!==0) return $arr['minutes'].'分钟前';
		if($arr['seconds']!==0) return $arr['seconds'].'秒钟前';
		return '1秒钟前';
	}
}
